package com.huashi.dealer.modular.business.express.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huashi.dealer.commonEntity.Express;
import com.huashi.dealer.modular.business.express.mapper.ExpressMapper;
import com.huashi.dealer.modular.business.express.service.ExpressService;
import com.huashi.dealer.modular.business.setting.vo.ExpressVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 物流公司服务实现类
 *
 * @author 自动生成
 * @since 2025-01-27
 */
@Service
public class ExpressServiceImpl extends ServiceImpl<ExpressMapper, Express> implements ExpressService {

    @Override
    public List<ExpressVo> getExpressList() {
        List<ExpressVo> list = new ArrayList<>();
        List<Express> expressList = this.list(new LambdaQueryWrapper<Express>().orderByAsc(Express::getSort));
        list = expressList.stream().map(express -> {
            ExpressVo expressVo = new ExpressVo();
            BeanUtils.copyProperties(express, expressVo);
            return expressVo;
        }).toList();
        return list;
    }

    @Override
    public String saveOrUpdateExpress(Express param) {
        if (param.getExpressId() != null && param.getExpressId() != 0L && param.getExpressId() != 0) {
            param.setUpdateTime(System.currentTimeMillis()/1000);
        }else{
            param.setCreateTime(System.currentTimeMillis()/1000);
            param.setUpdateTime(System.currentTimeMillis()/1000);
        }
        boolean ok = this.saveOrUpdate(param);
        return ok?"保存成功":"保存失败";
    }

    @Override
    public String deleteExpress(Long expressId) {
        int i = this.baseMapper.deleteById(expressId);
        return i>0?"删除成功":"删除失败";
    }
}
